import VitePluginVitepressDemo from '@pzy915/vite-plugin-vitepress-demo'
import { defineConfig } from 'vite'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { SearchPlugin } from '@pzy915/vitepress-plugin-search'
import { resolve, join } from 'node:path'
import { viteVueDocDataPlugin } from './plugins/vitepress-vue-doc-plugin'

const projectRoot = process.cwd()
export default defineConfig({
  plugins: [
    vueJsx(),
    viteVueDocDataPlugin('./src/**/*.vue'),
    VitePluginVitepressDemo({ glob: './**/demo/**/*.{vue,jsx,tsx,js,ts}' }),
    /**
     * flexsearch 配置: https://github.com/nextapps-de/flexsearch#options
     *
     * vitepress-plugin-simple-search 配置: https://github.com/stuyk/vitepress-plugin-simple-search
     *
     * @return  {[type]}  [return description]
     */
    SearchPlugin({
      // 最多包含的搜索结果条数
      previewLength: 30,
      buttonLabel: '搜索',
      placeholder: '文章搜索',
      /**
       * 采用分词器优化.
       *
       * 中文分词器：https://www.npmjs.com/package/@node-rs/jieba
       *
       * 字典配置：https://www.npmjs.com/package/nodejieba
       *
       * 相关文章: https://zhuanlan.zhihu.com/p/453803476
       */
      // tokenize: function (str) {
      //   console.log(str)
      //   return cut(str, false)
      // },
      tokenize: 'full',
    }),
  ],
  server: {
    // open: true,
    host: '0.0.0.0',
  },
  // resolve: {
  //   alias: {
  //     '~plugins': resolve(projectRoot, 'plugins'),
  //     '~articles': resolve(projectRoot, 'docs/articles'),
  //   },
  // },
})
